﻿using System;
using System.Collections.Generic;
using System.Text;

namespace hedefgrup.reports.common
{
    public static class Static
    {
        public static List<string> GetAuthorizedDealers(Report_Abstract report)
        {
            if (report.Context == null || report.Context.User == null)
            {
                return null;
            }

            string[] userDealerCodes = report.Context.User.getDealerCodes();

            if (userDealerCodes == null)
            {
                return null;
            }

            List<string> authorizedDealerCodes = new List<string>();

            foreach (string userDealerCode in userDealerCodes)
            {
                Tree dealer = report.GetDealer(userDealerCode);

                Tree currentTree = dealer;

                foreach (Tree child in currentTree.Children)
                {
                    authorizedDealerCodes.Add(child.Key);
                }

                while (currentTree != null)
                {
                    authorizedDealerCodes.Add
                    (
                        (
                        currentTree.Type == "coordinator" ? "Koordinatör " :
                        currentTree.Type == "area" ? "Bölge " :
                        ""
                        ) + currentTree.Key
                    );
                    currentTree = currentTree.Parent;
                }
            }
            return authorizedDealerCodes;
        }
    }
}
